* ============================================================================ *
* PROJECT:		Is Incumbency Advantage Gendered?
* AUTHOR: 		Semra Sevi 
* DATE:			2022-01-25
* ============================================================================ *

**********************
* Main models *
**********************

set scheme s1mono

*macro for axis scaling 
local x_y_settings "xscale(range(-30 30)) xlabel(-30(10)30) yscale(range(0 100)) ylabel(0(25)100)"
local x_y_settings_w "xscale(range(-20 20)) xlabel(-20(10)20) yscale(range(0 100)) ylabel(0(25)100)"
local x_y_settings_v "xscale(range(-20 20)) xlabel(-20(10)20) yscale(range(10 50)) ylabel(10(10)50)"

*RD Plots

** All candidates 

* Runs again as DV 
rdrobust runs_again margin_victory if year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num) all
	
* RD Plot: Runs again as DV						
rdplot runs_again margin_victory if margin_victory > - e(h_l) ///
	& margin_victory < e(h_r) & year >= 1990,   ///
	c(0) p(1) kernel(triangular) bwselect(mserd) nbins(20 20) binselect(qs) ///
	vce(nncluster prov_riding_num) graph_options(graphregion(color(white))   ///
	title("All candidates") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of rerunning at t") ///
	legend(off) `x_y_settings' saving("runsagain_everyone")) ci(95) 
	
* Elected as DV conditional on rerunning 
rdrobust elected_next margin_victory if year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num)	all	
	
* RD Plot: Elected as DV conditional on rerunning 						
rdplot elected_next margin_victory if margin_victory > - e(h_l) ///
	& margin_victory < e(h_r) & year >= 1990, ///
	c(0) p(1) kernel(triangular) bwselect(mserd) nbins(20 20) binselect(qs) ///
	vce(nncluster prov_riding_num)	graph_options(graphregion(color(white)) ///
	title("All candidates") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of winning at t") ///
	legend(off) `x_y_settings_w' saving("elected_everyone")) ci(95) 
	
* Result next as DV conditional on rerunning 
rdrobust percent_votes_next margin_victory if year >= 1990,  ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num)	all 
	
* RD Plot: Result next as DV conditional on rerunning 	
*color gs10 black 				
rdplot percent_votes_next margin_victory if margin_victory > - e(h_l) ///
	& margin_victory < e(h_r) & year >= 1990, ///
	c(0) p(1) kernel(triangular) bwselect(mserd) nbins(20 20) binselect(qs) ///
	vce(nncluster prov_riding_num) graph_options(graphregion(color(white)) ///
	title("All candidates") ///
	xtitle("Margin of victory at t-1") ytitle("Vote share at t") ///
	legend(off) `x_y_settings_v' saving("voteshare_everyone")) ci(95)		


*** Gender 
	
*Men

* Runs again as DV
rdrobust runs_again margin_victory if gender == 0 & year >= 1990,  ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num) all	
scalar N1 = e(tau_bc)
scalar D1 = e(se_tau_rb)
di N1
di D1


* RD Plot: Runs again as DV						
rdplot runs_again margin_victory if margin_victory > - e(h_l)  ///
	& margin_victory < e(h_r) & gender == 0 & year >= 1990, ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(10 10) ///
	vce(nncluster prov_riding_num) graph_options(graphregion(color(white)) ///
	title("Men") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of rerunning at t") ///
	legend(off) `x_y_settings' saving("runsagain_men")) ci(95)

	
* Women

* Runs again as DV
rdrobust runs_again margin_victory if gender == 1 & year >= 1990,  ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num)	all	
scalar N2 = e(tau_bc)
scalar D2 = e(se_tau_rb)
di N2
di D2	

	
* RD Plot: Runs again as DV						
rdplot runs_again margin_victory if margin_victory > - e(h_l) & ///
	margin_victory < e(h_r) & gender == 1 & year >= 1990, ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(10 10) ///
	vce(nncluster prov_riding_num) graph_options(graphregion(color(white)) ///
	title("Women") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of rerunning at t") ///
	legend(off) `x_y_settings' saving("runsagain_women")) ci(95) 
	
*comparing the RDD estimates between men and women
di abs(N1-N2)/sqrt(D1^2 + D2^2)	
	
gen rdmch = .
replace rdmch = 100 if _n == 1 | _n == 2 
h(rdmch)

* RDMC 	
*Runs again as DV
rdmc runs_again artificial_margin if year >= 1990,  ///
	cvar(artificial_cutoff) pvar(pv) kernelvar(kv) bwselectvar(bwsv) vcevar(vcev) ///
	pooled_opt(p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num))
	
lincom c1-c2 	
display r(estimate)/r(se)
	

* Men	
	
* Elected as DV conditional on rerunning 
rdrobust elected_next margin_victory if gender == 0 & year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num)	all
scalar N1 = e(tau_bc)
scalar D1 = e(se_tau_rb)
di N1
di D1	

scalar h_l_ = e(h_l) 
scalar h_r_  = e(h_r)	

	
* RD Plot: Elected as DV conditional on rerunning 						
rdplot elected_next margin_victory if margin_victory > - e(h_l) & ///
	margin_victory < e(h_r) & gender == 0 & year >= 1990, ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(10 10) ///
	vce(nncluster prov_riding_num) graph_options(graphregion(color(white)) ///
	title("Men") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of winning at t") ///
	legend(off) `x_y_settings_w' saving("elected_men")) ci(95)	
	
* Women
		
* Elected as DV conditional on rerunning 
rdrobust elected_next margin_victory if gender == 1 & year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num) all	
scalar N2 = e(tau_bc)
scalar D2 = e(se_tau_rb)
di N2
di D2	
	
	
* RD Plot: Elected as DV	conditional on rerunning 		 				
rdplot elected_next margin_victory if margin_victory > - e(h_l) & ///
	margin_victory < e(h_r) & gender == 1 & year >= 1990, ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(9 10)  ///
	vce(nncluster prov_riding_num)	graph_options(graphregion(color(white)) ///
	title("Women") ///
	xtitle("Margin of victory at t-1") ytitle("Pr. of winning at t") ///
	legend(off) `x_y_settings_w' saving("elected_women")) ci(95)

* comparing the RDD estimates between men and women
di abs(N1-N2)/sqrt(D1^2 + D2^2)		
		
* RDMC 	
* Elected next as DV
rdmc elected_next artificial_margin if year >= 1990, cvar(artificial_cutoff) ///
	pvar(pv) kernelvar(kv) bwselectvar(bwsv) vcevar(vcev) ///
	pooled_opt(p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num))
	
lincom c1-c2 
	
	
	
* Men	
	
* Result next as DV conditional on rerunning 
rdrobust percent_votes_next margin_victory if gender == 0 & year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num)	all
scalar N1 = e(tau_bc)
scalar D1 = e(se_tau_rb)
di N1
di D1	
	
* RD Plot: Result next as DV conditional on rerunning 						
rdplot percent_votes_next margin_victory if margin_victory > - e(h_l) & ///
	margin_victory < e(h_r) & gender == 0 & year >= 1990,  ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(10 10) ///
	vce(nncluster prov_riding_num)	graph_options(graphregion(color(white))  ///
	title("Men") ///
	xtitle("Margin of victory at t-1") ytitle("Vote share at t") ///
	legend(off) `x_y_settings_v' saving("voteshare_men")) ci(95)

	
* Women

* Result next as DV conditional on rerunning 
rdrobust percent_votes_next margin_victory if gender == 1 & year >= 1990, ///
	p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num) all
scalar N2 = e(tau_bc)
scalar D2 = e(se_tau_rb)
di N2
di D2	
			
	
* RD Plot: Result next as DV conditional on rerunning 						
rdplot percent_votes_next margin_victory if margin_victory > - e(h_l) & ///
	margin_victory < e(h_r) & gender == 1 & year >= 1990,  ///
	c(0) p(1) kernel(triangular) binselect(qs) nbins(10 10) ///
	vce(nncluster prov_riding_num)	graph_options(graphregion(color(white)) ///
	title("Women") ///
	xtitle("Margin of victory at t-1") ytitle("Vote share at t") ///
	legend(off) `x_y_settings_v' saving("voteshare_women")) ci(95)

	
* comparing the RDD estimates between men and women
di abs(N1-N2)/sqrt(D1^2 + D2^2)		


* RDMC 	
* Result next as DV
rdmc percent_votes_next artificial_margin if year >= 1990, cvar(artificial_cutoff) ///
	pvar(pv) kernelvar(kv) bwselectvar(bwsv) vcevar(vcev) ///
	pooled_opt(p(1) kernel(triangular) bwselect(mserd) ///
	vce(nncluster prov_riding_num))
	
lincom c1-c2 


*Combining graphs 

graph combine "runsagain_everyone.gph" "runsagain_men.gph" "runsagain_women.gph", rows(1) xsize(6) ysize(1.33) saving("runsagain.gph")

graph combine "elected_everyone.gph" "elected_men.gph" "elected_women.gph", rows(1) xsize(6) ysize(1.33) saving("elected.gph")

graph combine "voteshare_everyone.gph" "voteshare_men.gph" "voteshare_women.gph", rows(1) xsize(6) ysize(1.33) saving("voteshare.gph")


* Figure 3
graph combine "runsagain.gph" "elected.gph" "voteshare.gph", rows(3) saving("figure.gph")


		
		

		
		
	

	
	
	
	
